using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ShopForWeb.Model.Basic;

namespace ShopForWeb.Model.DBContexts
{
    public class ShopDBContext:DbContext
    {
        public ShopDBContext(DbContextOptions<ShopDBContext> options) : base(options) 
        { 
            
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<ShopCar>()
              .HasKey(o=>new{o.UserId, o.ProductId});
              modelBuilder.Entity<OrderDetail>()
              .HasKey(o => new { o.OrderId, o.ProductId });

              //唯一性索引
              modelBuilder.Entity<User>().HasIndex(o=>o.Phone).IsUnique();
              //种子数据
              modelBuilder.Entity<Admin>().HasData(new Admin()
              { 
                AdminId=1,
                AdminName="admin",
                Phone="19555352680",
                Password="1234"
              }
              );

        }

      public DbSet<User>UserSet{get;set;}=null!;
      public DbSet<Admin>AdminSet{get;set;}=null!;
      public DbSet<Advertisement>AdvertisementSet{get;set;}=null!;
      public DbSet<Category>CategorySet{get;set;}=null!;
       public DbSet<Order>OrderSet{get;set;}=null!;
      public DbSet<OrderDetail>OrderDetailSet{get;set;}=null!;
      public DbSet<Partner>PartnerSet{get;set;}=null!;
      public DbSet<Review>ReviewSet{get;set;}=null!;
      public DbSet<Product>ProductSet{get;set;}=null!;
      public DbSet<ShopCar>ShopCarSet{get;set;}=null!;
    
    }
        
}